package com.fj.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fj.condition.UserRegisterCondition;
import com.fj.response.Result;
import com.fj.response.ResultCode;
import com.fj.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "用户管理")
@CrossOrigin
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/checkUser")
    public Result checkUser(String name) {
        if (!StringUtils.isBlank(name)) {
            boolean fig = userService.checkUser(name);
            if(fig){
                return Result.ok();
            }else {
                return Result.error();
            }
        } else {
            return Result.error(ResultCode.PARAM_IS_BLANK);
        }
    }

    @ApiOperation(value = "用户注册",notes = "根据手机号或邮箱注册")
    @PostMapping("/userRegistry")
    public Result userRegistry(@RequestBody UserRegisterCondition userRegisterCondition,@RequestParam String registryType){
        userService.userRegistry(userRegisterCondition,registryType);
        return Result.ok();
    }

    @ApiOperation(value = "用户激活",notes = "根据手机号或邮箱激活")
    @PostMapping("/activatedUser")
    public Result activatedUser(@RequestParam String userCode,@RequestParam String code){
        boolean flag = userService.activatedUser(userCode,code);
        return flag?Result.ok():Result.error();
    }
}
